package com.eduspace.eduplatform.wares.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;

import javax.sql.DataSource;

/**
 * @author tbc on 2016/11/21 09:27:45.
 */
@Configuration
@ComponentScan({
        "com.eduspace.eduplatform.wares"
})
@EnableTransactionManagement
public class SpringConfiguration {

    @Bean
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }


    //    <!-- 配置事务管理器，注意这里的dataSource和SqlSessionFactoryBean的dataSource要一致，不然事务就没有作用了 -->
//    <bean id="transactionManager"
//    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
//        <property name="dataSource" ref="dataSource"/>
//    </bean>
//    <!-- 事务注解驱动，标注@Transactional的类和方法将具有事务性 -->
//    <tx:annotation-driven transaction-manager="transactionManager"/>
    @Bean
    public DataSourceTransactionManager getDataSourceTransactionManager(DataSource dataSource) {
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
        transactionManager.setDataSource(dataSource);
        return transactionManager;
    }
}
